package immutablecollections;

import java.util.*;
/**
 * An iterator on an {@link ImRoseTreeZipper}.
 * 
 * Because `ImRoseTreeZippers` are immutable, {@link #remove} will throw {@link UnsupportedOperationException}.
 * 
 * @see ImRoseTree
 * @see ImRoseTreeZipper
 * @see ImRoseTreeIterator
 *
 */
public class ImRoseTreeZipperIterator<T> implements Iterator<ImRoseTreeZipper<T>>
{

    private ImRoseTreeZipper<T> zipper;
    private boolean offLeft = true;

    public ImRoseTreeZipperIterator(final ImRoseTreeZipper<T> zipper)
    {
        this.zipper = zipper;
    }

    public boolean hasNext()
    {
        return offLeft
                ? true
                : zipper.hasNext();
    }

    public ImRoseTreeZipper<T> next()
    {
        if (offLeft)
        {
            offLeft = false;
            return zipper;
        }

        if (!hasNext())
            throw new NoSuchElementException();

        zipper = zipper.next();
        return zipper;
    }

    public void remove()
    {
        throw new UnsupportedOperationException();
    }

}
